package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

import com.geologyoa.domain.Dwqk01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;


public class SerachDwqk01Servlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
       doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SystemManager sys=new SystemManagerImpl();
		String DWQK0102=request.getParameter("DWQK0102");//单位统一编号
		String DWQK0103=request.getParameter("DWQK0103");//单位名称
		
		String DWQK0104=request.getParameter("DWQK0104");//成立时间起
		String DWQK0104s=request.getParameter("DWQK0104s");//成立时间起
		String DWQK0104e=request.getParameter("DWQK0104e");//成立时间止
		String DWQK0105=request.getParameter("DWQK0105");//单位地址
		String DWQK0107=request.getParameter("DWQK0107");//单位性质
		String DWQK0108=request.getParameter("DWQK0108");//主管部门
		String DWQK0110=request.getParameter("DWQK0110");//法定代表人
		String ZZType=request.getParameter("DWZZ0104");//单位资质
		String ZZLevel=request.getParameter("DWZZ0105");//单位资质级别
		String DWQK0116 = request.getParameter("DWQK0116");//变更记录
		String DWQK0117 = request.getParameter("DWQK0117");//状态
		List<Dwqk01> dwqkList =null;
		if(ZZType==null||ZZType.equals("")){
			dwqkList=sys.SerachDwqk(DWQK0102,DWQK0103, DWQK0104s,DWQK0104e,DWQK0105, DWQK0107,DWQK0108, DWQK0110,DWQK0116,DWQK0117);
		}else{
		//ZZType= "危评";
			dwqkList=sys.SerachDwqkByZZType(DWQK0103, DWQK0104, DWQK0107, DWQK0110, ZZType, ZZLevel);
		}
		Document document=DocumentHelper.createDocument();
		if(dwqkList!=null)
		{
			Element fwlistElement =document.addElement("dwqkList");
			fwlistElement.addAttribute("size", (new StringBuilder(String.valueOf(dwqkList.size()))).toString());
			Dwqk01 dwqk01;
			Element fwElement;
			for(Iterator iterator=dwqkList.iterator();iterator.hasNext();)
			{
				dwqk01 = (Dwqk01)iterator.next();
				fwElement=fwlistElement.addElement("dwqkInfo");
				fwElement.addAttribute("DWQK0101", dwqk01.getDwqk0101().toString());
				fwElement.addAttribute("DWQK0102", dwqk01.getDwqk0102());
				fwElement.addAttribute("DWQK0103", dwqk01.getDwqk0103());
				fwElement.addAttribute("DWQK0104", dwqk01.getDwqk0104());
				fwElement.addAttribute("DWQK0105", dwqk01.getDwqk0105());
				fwElement.addAttribute("DWQK0106", dwqk01.getDwqk0106());
				fwElement.addAttribute("DWQK0107", dwqk01.getDwqk0107());
				fwElement.addAttribute("DWQK0108", dwqk01.getDwqk0108());
				fwElement.addAttribute("DWQK0109", new DecimalFormat("0.00").format(dwqk01.getDwqk0109()));
				fwElement.addAttribute("DWQK0110", dwqk01.getDwqk0110());
				fwElement.addAttribute("DWQK0111", dwqk01.getDwqk0111());
				fwElement.addAttribute("DWQK0113", dwqk01.getDwqk0113());
				fwElement.addAttribute("DWQK0114", dwqk01.getDwqk0114());
				fwElement.addAttribute("DWQK0116", dwqk01.getDwqk0116());
				fwElement.addAttribute("DWQK0117", dwqk01.getDwqk0117());
				fwElement.addAttribute("DWQK0118", dwqk01.getDwqk0118());
				fwElement.addAttribute("DWZZ0104", dwqk01.getDwzz0104());
				fwElement.addAttribute("DWZZ0105", dwqk01.getDwzz0105());
				
			}
		}
		StringWriter xmlout = new StringWriter();
		XMLWriter output = new XMLWriter(xmlout);
		output.write(document);
		response.setContentType("text/html;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Pragma", "No-cache");
		response.getWriter().write(xmlout.toString());
	}

}
